package control.networking;

import java.util.ArrayList;
import java.util.List;

/**
 * Keeps track of who is connected to the chat room.
 * Main utility is in being able to broadcast to the
 * group when someone sends a message.
 * 
 */
public class ConnectedChatters {
	static List<ChatServerHandler> chatters;
	
	/**
	 * Initializes a ConnectedChatters class.
	 */
	public ConnectedChatters() {
		chatters = new ArrayList<ChatServerHandler>();
	}
	
	/**
	 * Broadcasts the objects to all of the other gamers connected so that
	 * they may update their client with the current Map.
	 * @param o Object instance
	 */
	public void broadcast( String message ) {
		System.out.println("ConnectedChatters: broadcast() was just called");
		for(ChatServerHandler client : chatters ){
			client.displayMessage( message );
		}	
	}
	
	/**
	 * Adds a chatter to the ConnectedChatters group.
	 * @param cc A ChatServerHandler
	 * @return boolean
	 */
	public boolean addChatter(ChatServerHandler cc) {
		// TODO Add control to make sure client is not already connected.
		return chatters.add(cc);
	}

	/**
	 * Removes a disconnected chatter from group.
	 * @param cc ChatServerHandler
	 * @return boolean
	 */
	public boolean removeChatter(ChatServerHandler cc) {
		return chatters.remove(cc);
	}

	/**
	 * Will print the list of who is connected to the ChatServer
	 * to the text box in the GUI.
	 * @return String
	 */
	public static String printChatters() {
		return "Kevin is the only chatter right now";
	}
	
	/**
	 * Returns the size of the group of chatters.
	 * @return int
	 */
	public int getSize() {
		return chatters.size();
	}

	
}
